<!DOCTYPE html>
<html lang='en'>
<head>
    <meta charset='UTF-8'>
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>
    <title>Document</title>
    <script type='text/javascript' src='../js/vue.js'></script>
    <script src="../js/vue-router_3.0.2.js"></script>
</head>
<body>
    <div id='app'>
        <router-link to="/index">主页</router-link>
        <router-link to="/post">文章</router-link>
        <!-- <router-link to="/category">分类</router-link> -->
        <router-link to="/category/life">生活馆1</router-link>
        <router-link to="/category/travel">爱旅游</router-link>
        <router-link to="/category/sport">运动馆</router-link>
        <router-view></router-view>
    </div>
    <script type='text/javascript'>
        const Index = {
            template: `<div><h1>这是主页页面</h1></div>`
        }
        const Post = {
            template: `<div><h1>这是文章页面</h1></div>`
        }
        const Category = {
            template: `<div>
                <h1>这是===={{$route.params.name}}===分类页面</h1>
                <hr>

            </div>`
        }
        const Life = {
            //组件中通过props接收路由传递的参数，在路由模块中需要定义props为true
            props: ['name'],
            template: `<div>
                <!-- <h1>欢迎来到====={{$route.params.id}}====号生活馆</h1> -->
                <h1>欢迎来到====={{name}}====号生活馆</h1>
            </div>`
        }
        const Sport = {
            template: `<div><h1>欢迎来到运动馆</h1></div>`
        }

        const router = new VueRouter({
            routes: [
                { path: '/', redirect: '/index'},
                { path: '/index', component: Index},
                { path: '/post', component: Post},
                { path: '/category/:name', component: Category, props: true}
            ]
        })

        var vm = new Vue({
            el: '#app',
            data: {
                msg: 'Hello Vue'
            },
            router
        });
    </script>
</body>
</html>